package com.yang.service.adminimpl;

import com.yang.bean.MarketSystem;
import com.yang.bean.bj.vo.MarketExpressVO;
import com.yang.bean.bj.vo.MarketMallVO;
import com.yang.bean.bj.vo.MarketOrderVO;
import com.yang.bean.bj.vo.MarketWxVO;
import com.yang.mapper.MarketMallMapper;
import com.yang.service.admin.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @description: TOOD
 * @return:
 * @author: BaoZi
 * @date: 2022/9/7
 */
@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    MarketMallMapper mallMapper;

    @Override
    public MarketMallVO queryMarket() {

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("market_mall_latitude");
        arrayList.add("market_mall_name");
        arrayList.add("market_mall_qq");
        arrayList.add("market_mall_longitude");
        arrayList.add("market_mall_phone");
        arrayList.add("market_mall_address");

        HashMap<String, String> map = new HashMap<>();
        for (String s : arrayList) {
            //遍历arrayList,根据key_name 循环查询key_value
            //再把key_name，key_value保存到map
            MarketSystem marketSystem = mallMapper.selectMarketMall(s);
            map.put(s,marketSystem.getKeyValue());
        }
        MarketMallVO mallVO = new MarketMallVO();

        //根据key取出value赋值给VO
        mallVO.setMarket_mall_latitude(map.get("market_mall_latitude"));
        mallVO.setMarket_mall_name(map.get("market_mall_name"));
        mallVO.setMarket_mall_qq(map.get("market_mall_qq"));
        mallVO.setMarket_mall_longitude(map.get("market_mall_longitude"));
        mallVO.setMarket_mall_phone(map.get("market_mall_phone"));
        mallVO.setMarket_mall_address(map.get("market_mall_address"));
        return mallVO;
    }

    @Override
    public MarketExpressVO queryMarketExpress() {

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("market_express_freight_min");
        arrayList.add("market_express_freight_value");

        HashMap<String, String> map = new HashMap<>();
        for (String s : arrayList) {
            MarketSystem marketSystem = mallMapper.selectMarketExpress(s);
            map.put(s,marketSystem.getKeyValue());
        }
        MarketExpressVO expressVO = new MarketExpressVO();
        expressVO.setMarket_express_freight_min(map.get("market_express_freight_min"));
        expressVO.setMarket_express_freight_value(map.get("market_express_freight_value"));
        return expressVO;
    }

    @Override
    public MarketOrderVO queryMarketOrder() {

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("market_order_unpaid");
        arrayList.add("market_order_unconfirm");
        arrayList.add("market_order_comment");

        HashMap<String, String> map = new HashMap<>();
        for (String s : arrayList) {
            MarketSystem marketSystem = mallMapper.selectMarketOrder(s);
            map.put(s,marketSystem.getKeyValue());
        }
        MarketOrderVO marketOrderVO = new MarketOrderVO();
        marketOrderVO.setMarket_order_unpaid(map.get("market_order_unpaid"));
        marketOrderVO.setMarket_order_unconfirm(map.get("market_order_unconfirm"));
        marketOrderVO.setMarket_order_comment(map.get("market_order_comment"));
        return marketOrderVO;
    }

    @Override
    public MarketWxVO queryMarketWx() {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("market_wx_index_new");
        arrayList.add("market_wx_index_topic");
        arrayList.add("market_wx_share");
        arrayList.add("market_wx_index_brand");
        arrayList.add("market_wx_catlog_goods");
        arrayList.add("market_wx_catlog_list");
        arrayList.add("market_wx_index_hot");
        MarketWxVO marketWxVO = new MarketWxVO();

        HashMap<String, String> map = new HashMap<>();
        for (String s : arrayList) {
            MarketSystem marketSystem = mallMapper.selectMarketWx(s);
            map.put(s, marketSystem.getKeyValue());
        }
        marketWxVO.setMarket_wx_index_new(map.get("market_wx_index_new"));
        marketWxVO.setMarket_wx_index_topic(map.get("market_wx_index_topic"));
        marketWxVO.setMarket_wx_share(map.get("market_wx_share"));
        marketWxVO.setMarket_wx_index_brand(map.get("market_wx_index_brand"));
        marketWxVO.setMarket_wx_catlog_goods(map.get("market_wx_catlog_goods"));
        marketWxVO.setMarket_wx_catlog_list(map.get("market_wx_catlog_list"));
        marketWxVO.setMarket_wx_index_hot(map.get("market_wx_index_hot"));
        return marketWxVO;
    }
}
